import datetime
import random
from function_tool import time_format_transform
import pymysql

import clickhouse_connect

connect_info = {
    'port': 8123,
    'host': '192.168.104.243',
    'username': 'default',
    'password': 'bwda2025',
    'database': 'lap'
}
mysql_connect_info = {
    'port': 3306,
    'host': '192.168.2.142',
    'user': 'root',
    'password': 'cI5v4N2Q%a',
    'database': 'lap'
}
mysql_connection = pymysql.connect(**mysql_connect_info)
mysql_cursor = mysql_connection.cursor()
sql = """
        select distinct bag.dept_id, sd.name, bag.dept_parent_id
        from bpm_audit_group bag
        left join system_dept sd on sd.id = bag.dept_id
        where bag.deleted = 0 and bag.dept_id not in (1)
"""
mysql_cursor.execute(sql)
result = mysql_cursor.fetchall()
mysql_cursor.close()
mysql_connection.close()
client = clickhouse_connect.get_client(**connect_info)
column_list = ['id', 'op_time', 'bwd_create_time', 'master_account_id', 'master_account_name', 'master_account_type',
               'master_org_id', 'master_org_name', 'master_parent_org_id', 'op_content', 'op_result',
               'slave_account_name', 'slave_account_id', 'slave_account_type', 'mobile', 'id_card']
table_name = 'ads_third_party_use_admin_acct_local'
insert_data = []
master_account = [{'account': 'luffy', 'name': '路飞'}, {'account': 'zoro', 'name': '索隆'},
                  {'account': 'nami', 'name': '娜美'},
                  {'account': 'usopp', 'name': '乌索普'}, {'account': 'sanji', 'name': '山治'},
                  {'account': 'chopper', 'name': '乔巴'},
                  {'account': 'robin', 'name': '罗宾'}, {'account': 'franky', 'name': '弗兰科'},
                  {'account': 'brook', 'name': '布鲁克'}, {'account': 'jinbe', 'name': '甚平'}]
master_account_type_list = ['0', '1']
length0 = len(result)
length1 = len(master_account)
op_result_list = ['0', '1']
for i in range(500000):
    index0 = random.randint(0, length0 - 1)
    index1 = random.randint(0, length1 - 1)
    sid = str(random.randint(10 ** 14, 10 ** 16))
    bwd_create_time = time_format_transform.TimeFormatTransform().get_random_date('2025-10-01', '2025-10-31')
    op_time = bwd_create_time
    master_account_id = master_account[index1]['account']
    master_account_name = master_account[index1]['name']
    master_account_type = random.choice(master_account_type_list)
    master_org_id = str(result[index0][0])
    master_org_name = result[index0][1]
    master_parent_org_id = str(result[index0][2])
    op_content = 'select * from basic_data_org'
    op_result = random.choice(op_result_list)
    slave_account_name = 'root账号'
    slave_account_id = 'root'
    slave_account_type = '0'
    mobile = str(random.randint(13000000001, 19999999999))
    id_card = str(random.randint(100000000000000000, 9999999999999999999))
    insert_data.append([sid, op_time, bwd_create_time, master_account_id, master_account_name, master_account_type,
                        master_org_id, master_org_name, master_parent_org_id, op_content, op_result, slave_account_name,
                        slave_account_id, slave_account_type, mobile, id_card])
client.insert(table_name, insert_data, column_list)
client.close()
